package com.job.liushuang.HomeWork0716;

import java.util.Calendar;
import java.util.Date;

/**
 * @author Liushuang
 * @version 1.0
 * @since 2022-07-16 19:38:01
 */
public class UseCalendar {
    public static void main(String[] args) {
        //获取当前时间的日历对象
        Calendar now=Calendar.getInstance();
        System.out.println(now);
        //获取各种字段值
        int year=now.get(Calendar.YEAR);
        int month=now.get(Calendar.MONTH)+1;
        int day=now.get(Calendar.DAY_OF_MONTH);
        System.out.println(year+"-"+month+"-"+day);
        //修改
        //now.set(Calendar.HOUR_OF_DAY,20);
        //System.out.println(now);

        //在年上面找历史 之前39年
        now.add(Calendar.YEAR, -39);
        System.out.println(now);//2019-4月

        //跟日期对象的转换
        //Date rightNow = new Date();
        //1:用日期时间 重置日历
        //now/setTime(rightNow);
        //System.out.println(now);
        //2:获取日历表示时间的日期对象
        Date date=now.getTime();
        System.out.println(date);
    }
}
